package router

import (
	"fitness/api/client"
	"fitness/api/request"
	"fitness/rpc/proto/user"
	"github.com/gin-gonic/gin"
	"net/http"
)

func UserLogin(c *gin.Context) {
	var data request.User
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "未接收参数",
			"data": nil,
		})
		return
	}
	login, err := client.UserLogin(c, &user.UserLoginReq{
		Phone:    data.Phone,
		Password: data.Password,
		Code:     data.Code,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "用户登录失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 1,
		"msg":  "用户登录成功",
		"data": login,
	})
}

func FitnessList(c *gin.Context) {
	var data request.Fitness
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "未接收参数",
			"data": nil,
		})
		return
	}
	list, err := client.FitnessList(c, &user.FitnessListReq{})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "展示失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 1,
		"msg":  "用户展示成功",
		"data": list,
	})
}

func FitnessLike(c *gin.Context) {
	var data request.Fitness
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "未接收参数",
			"data": nil,
		})
		return
	}
	list, err := client.FitnessLike(c, &user.FitnessLikeReq{})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "推荐展示失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 1,
		"msg":  "推荐展示成功",
		"data": list,
	})
}
